<template>
	<view>

		<u-empty mode="news" icon="http://cdn.uviewui.com/uview/empty/news.png" v-if="stageInfoList.length==0"
			text="您所在的区域商城暂未开放期待您的加入!">
		</u-empty>

		<view class="u-flex u-row-center u-m-80" v-if="stageInfoList.length==0">
			<view class="u-m-r-20"  style="width: 40%;">
				<u-button text="我要加盟" color="#FF5B00" style="width: 100%;"
					@click="$u.route('pages/index/partnership/partnership')"></u-button>
			</view>
			<view class="u-m-l-20"  style="width: 40%;">
				<u-button text="返回主页" style="width: 100%;" @click="backIndex"></u-button>
			</view>
		</view>

		<view v-for="(item,k) in stageInfoList" :key="k" class="card u-p-l-20 u-p-r-20 u-p-t-24"
			@click="handleGoBack(item)">
			<view class="text-black u-font-32">{{item.housingName}}（{{item.companyLianxiPhone}}）</view>
			<view class="flex align-center justify-between">
				<view class="u-font-24 u-m-t-16 text999">{{item.equAddress}}</view>
				<view class="flex align-center" @click="handleCallPhone(item.companyLianxiPhone)">
					<u-icon class="u-m-r-48" name="/static/index/mobile.png" size="54rpx"></u-icon>
				</view>
			</view>
			<view class="u-m-t-16">
				<text class="u-font-xs text999">距离</text>
					<text class="u-font-xs text999">{{parseFloat(item.distance).toFixed(2)}}米</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getEquInfoList
	} from "@/common/api/api.js"
	export default {
		data() {
			return {
				stageInfoList: [],
			}
		},
		onLoad() {
			this.handleGetEquInfoList();
		},
		methods: {
			handleGetEquInfoList() {
				let that = this;
				uni.getLocation({
					type: 'gcj02', //gcj02
					// altitude: true,
					// geocode:true,
					success: function(res) {
						let lat = res.latitude;
						let lng = res.longitude;
						console.log("lat,lan", lat, lng, res);
						getEquInfoList({
							lng: lng,
							lat: lat
						}).then(res => {
							that.stageInfoList = res.data.list;
						})
					},
					fail: function(e) {
						console.log('定位失败')
						console.log(e)
					}
				})
			},
			// 选中后的跳转
			handleGoBack(item) {
				// 返回时传递数据
				uni.navigateBack({
					delta: 1,
					success: () => {
						uni.$emit('stageBackShop', item)
					}
				})

			},
			handleCallPhone(phone) {
				uni.makePhoneCall({
					phoneNumber: '' + phone
				})
			},
			backIndex() {
				uni.$u.route({
					url: '/pages/index/index',
					type: 'reLaunch'
				})
			}
		}
	}
</script>

<style>
	.card {
		width: 686rpx;
		height: 220rpx;
		background: #FFFFFF;
		border-radius: 8rpx;
		margin-left: 32rpx;
		margin-right: 32rpx;
		margin-top: 20rpx;
	}
</style>